import { request } from '../utils/request';

export interface CallGraphQuery {
  unitId: string;
  target: string;
  queryType?: 'METHOD' | 'TABLE';
  depth?: number;
  includeUpstream?: boolean;
  includeDownstream?: boolean;
  entryMethodsOnly?: boolean;
  maxNodes?: number;
}

export async function queryCallGraph(data: CallGraphQuery) {
  return request({ url: '/call-graph/query', method: 'post', data });
}

export async function getSuggestions(params: { unitId: string; keyword: string; type?: 'METHOD' | 'TABLE' }) {
  return request({ url: '/call-graph/suggestions', method: 'get', params });
}

export async function expandNode(data: { unitId: string; nodeId: string; direction?: 'UPSTREAM' | 'DOWNSTREAM' | 'BOTH'; depth?: number; maxNodes?: number; }) {
  return request({ url: '/call-graph/expand', method: 'post', data });
}

export async function getNodeDetails(nodeId: string) {
  return request({ url: `/call-graph/node/${nodeId}/details`, method: 'get' });
}

export async function getRecommendedPath(unitId: string) {
  return request({ url: '/call-graph/recommended', method: 'get', params: { unitId } });
}

